/**
 * Copyright (C), 2019-2022, 宇信融汇
 * FileName: PublisherBoot
 * Author:   666
 * Date:     2022/4/21 14:07
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 666           修改时间           版本号              描述
 */
package com.mashibing.rabbitmq_boot;

/**
 * @Classname PublisherBoot
 * @Description Springboot的生产测试类
 * @Date 2022/4/21 14:07
 * @Created by 666
 */
//@SpringBootTest
//public class PublisherBoot {
//    @Autowired
//    public RabbitTemplate rabbitTemplate;
//
//    @Test
//    public void publisher() {
//        for (int i = 0; i < 10; i++) {
//            rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, "big.black.dog", "message");
//            System.out.println("生产者消费发送成功");
//        }
//
//    }
//
//    //需要添加特殊属性
//    @Test
//    public void publisherWithProess() {
//        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, "big.black.dog", "message", new MessagePostProcessor() {
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                message.getMessageProperties().setCorrelationId("535345");
//                return message;
//            }
//        });
//    }
//
//
//    //开启comfirm
//    @Test
//    public void publisherWithConfirm() {
////        1、设置confirm
//        rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {
//            @Override
//            public void confirm(CorrelationData correlationData, boolean ack, String cause) {
//                if (ack) {
//                    System.out.println("消息已经发送给交换机");
//                } else {
//                    System.out.println("消息没有发送exchange,需要进行补救");
//                }
//            }
//        });
//        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, "big.black.dog", "withconfirmmessage");
//        System.out.println("消息发送成功");
//    }
//
//    @Test
//    public void publisherWithReturn() {
//        //1、开启return
//        rabbitTemplate.setReturnsCallback(new RabbitTemplate.ReturnsCallback() {
//            @Override
//            public void returnedMessage(ReturnedMessage returned) {
//                String message = returned.getMessage().toString();
//                System.out.println("消息" + message + "发送queue失败，需要做补救操作");
//
//            }
//        });
//        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, "big.black1.dog", "withReturnMessage");
//        System.out.println("消息发送成功");
//    }
//
//    @Test
//    public void publisherWithBasicProperties() {
//        //持久化
//        rabbitTemplate.convertAndSend(RabbitMQConfig.EXCHANGE, "big.black.dog", "publisherWithBasicProperties", new MessagePostProcessor() {
//            @Override
//            public Message postProcessMessage(Message message) throws AmqpException {
//                //设置持久化
//                message.getMessageProperties().setDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
//                return message;
//            }
//        });
//        System.out.println("消息发送成功");
//
//    }
//}
